package com.juyu.miliao.api.controller;


import com.juyu.miliao.api.domain.VipPay;
import com.juyu.miliao.api.service.VipPayService;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 马甲包需求
 */
@RestController
@RequestMapping("/vipPay")
public class VipPayController {

    @Resource
    VipPayService vipPayService;

    /**
     * 获取vip信息
     *
     * @param type 1:购买qq 2:购买微信
     * @return
     */
    @GetMapping("/{hostUserId}/{type}")
    public List<VipPay> getVipPayListByUserId(HttpServletRequest request, Authentication token,
                                              @PathVariable("hostUserId") long hostUserId,
                                              @PathVariable("type") int type) {
        Subject subject = (Subject) token.getPrincipal();
        return vipPayService.getVipPayByUserId(subject.getId(), hostUserId, type);
    }

    /**
     * 赠送金币
     * type 1:购买qq 2:购买微信
     */
    @PostMapping("/payContact")
    public void payContact(HttpServletRequest request, Authentication token,
                           @RequestParam("hostUserId") long hostUserId,
                           @RequestParam("type") int type) {
        Subject subject = (Subject) token.getPrincipal();
        vipPayService.payContact(subject.getId(), hostUserId, type);
    }
}
